// stores/editorStore.js
import { defineStore } from 'pinia';
import { ref } from 'vue';

export const useEditorStore = defineStore('editor', () => {
  // state
  const hasUnsavedChanges = ref(false); // 是否有未保存的更改
  const isSaving = ref(false); // 是否正在保存
  const saveError = ref(null); // 保存错误信息
  const lastSavedTime = ref(null); // 最后保存时间

  // actions
  const setHasUnsavedChanges = (value) => {
    hasUnsavedChanges.value = value;
  };

  //   const setSaving = (value) => {
  //     isSaving.value = value;
  //   };

  //   const setSaveError = (error) => {
  //     saveError.value = error;
  //   };

  //   const setLastSavedTime = (time) => {
  //     lastSavedTime.value = time;
  //   };

  // 返回所有状态和方法
  return {
    hasUnsavedChanges,
    isSaving,
    saveError,
    lastSavedTime,
    setHasUnsavedChanges,
    // setSaving,
    // setSaveError,
    // setLastSavedTime,
  };
});
